*Table A.18: Snack Treatment effects on Body Mass Index and Diet of Adults
cd ""

use master_data_adults_child_s13456_shared.dta, clear 

drop meal_control snack_control
gen meal_control=1 if treatment==2
replace meal_control=0 if treatment==1

gen snack_control=1 if treatment==3
replace snack_control=0 if treatment==1

drop if type_id=="X" // **Dropping newborns born during the three years of study
drop if id=="3885553B" //**error in the id number and empty data
drop if id=="3885553G" //**error in the id number and empty data
replace treatment=2 if id=="38855553B" //**retrieving the correct treatment for this id
replace treatment=2 if id=="38855553G" //**retrieving the correct treatment for this id
drop if id=="101aa22c" //**this id does not exist

********************************************************************************
ge meal=(treatment==2)
replace meal=. if treatment==.

ge snack=(treatment==3)
replace snack=. if treatment==.

ge session1=(session==1)
replace session1=. if session==.

ge session3=(session==3)
replace session3=. if session==.

ge session4=(session==4)
replace session4=. if session==.

ge session5=(session==5)
replace session5=. if session==.

ge session6=(session==6)
replace session6=. if session==.

ge meal_session1=meal*session1
ge meal_session3=meal*session3
ge meal_session4=meal*session4
ge meal_session5=meal*session5
ge meal_session6=meal*session6

ge snack_session1=snack*session1
ge snack_session3=snack*session3
ge snack_session4=snack*session4
ge snack_session5=snack*session5
ge snack_session6=snack*session6

********************************************************************************
xtreg  bmi session3 session4 session5 session6 meal_session3 meal_session4 meal_session5 meal_session6 snack_session3 snack_session4 snack_session5 snack_session6 if child==0, cluster(hh_id) fe
test meal_session3 meal_session4 meal_session5 meal_session6
test snack_session3 snack_session4 snack_session5 snack_session6


use "master_data_adults_child_s13456_shared.dta", clear 
joinby id session using "Supermarket_data_short_S56_EDIandESSEX_STATA.dta", unmatched(both)

drop meal_control snack_control
gen meal_control=1 if treatment==2
replace meal_control=0 if treatment==1
tab meal_control

gen snack_control=1 if treatment==3
replace snack_control=0 if treatment==1
tab snack_control

drop if type_id=="X" // **Dropping newborns born during the three years of study
drop if id=="3885553B" //**error in the id number and empty data
drop if id=="3885553G" //**error in the id number and empty data
replace treatment=2 if id=="38855553B" //**retrieving the correct treatment for this id
replace treatment=2 if id=="38855553G" //**retrieving the correct treatment for this id
drop if id=="101aa22c" //**this id does not exist
drop if id=="27655663" //**outlier on many measurements


*variables created
ge food15_other_veg_new=food15_other_veg
replace food15_other_veg_new=0 if food15_other_veg==. & energykcal!=.

ge food16_fruit_new=food16_fruit
replace food16_fruit_new=0 if food16_fruit==. & energykcal!=.

su food15_other_veg 
su food16_fruit 
su food15_other_veg_new 
su food16_fruit_new

*
drop portion_veg_wisp portion_fruit_wisp
gen portion_veg_wisp=food15_other_veg/80
gen portion_fruit_wisp=food16_fruit/80
gen fuit_and_veg_g=total_veg_fruit_eatwell if session==1
replace fuit_and_veg_g=total_veg_fruit_eatwell if session==3
replace fuit_and_veg_g=food15_other_veg+food16_fruit if session==4

ge FV=food15_other_veg_new+food16_fruit_new


* Self reported changes in fruit and vegetables consumption
* adults
* simply counting changes (no change is equal to 0, decreases are negative, increases are positive)
gen n_change_FV=consumption_fresh_fruit+consumption_fresh_vegetables-4
gen n_change_fat=consumption_processed_meat+consumption_fried+consumption_burgers_pizza+consumption_crisps+consumption_veg_crisps+consumption_salted_peanuts+consumption_unsalted_nuts+consumption_pretzels_crackers-16
gen n_change_sugar=consumption_pies+consumption_cakes+consumption_doughnut+consumption_candies+consumption_ice_cream+consumption_energy_bar+consumption_breakfast_bar+consumption_soft_drinks-16
* different variable for session 3
replace n_change_FV=change_cons_fresh_fruit+change_cons_fresh_vegetables-4 if session==3
replace n_change_fat=change_cons_processed_meat+change_cons_fried+change_cons_burgers_pizza+change_cons_crisps+change_cons_veg_crisps+change_cons_salted_peanuts+change_cons_unsalted_nuts+change_cons_pretzels_crackers-16 if session==3
replace n_change_sugar=change_cons_pies+change_cons_cakes+change_cons_doughnut+change_cons_candies+change_cons_ice_cream+change_cons_energy_bar+change_cons_breakfast_bar+change_cons_soft_drinks-16 if session==3


* children
* simply counting changes (no change is equal to 0, decreases are negative, increases are positive)
gen child_n_change_FV=child_consumption_fresh_fruit+child_consumption_fresh_vegetabl-4
gen child_n_change_fat=child_consumption_processed_meat+child_consumption_fried+child_consumption_burgers_pizza+child_consumption_crisps+child_consumption_veg_crisps+child_consumption_salted_peanuts+child_consumption_unsalted_nuts+child_consumption_pretzels_crack-16
gen child_n_change_sugar=child_consumption_pies+child_consumption_cakes+child_consumption_doughnut+child_consumption_candies+child_consumption_ice_cream+child_consumption_energy_bar+child_consumption_breakfast_bar+child_consumption_soft_drinks-16
*session 3
replace child_n_change_FV=child_change_cons_fresh_fruit+child_change_cons_fresh_vegetabl-4 if session==3
replace child_n_change_fat=child_change_cons_processed_meat+child_change_cons_fried+child_change_cons_burgers_pizza+child_change_cons_crisps+child_change_cons_salted_peanuts+child_change_cons_veg_crisps+child_change_cons_unsalted_nuts+child_change_cons_pretzels_crack-16 if session==3
replace child_n_change_sugar=child_change_cons_pies+child_change_cons_cakes+child_change_cons_doughnut+child_change_cons_candies+child_change_cons_ice_cream+child_change_cons_energy_bar+child_change_cons_breakfast_bar+child_change_cons_soft_drinks+child_energy_drinks-16 if session==3

*assigning the values to children (they were in the row for adults)
bys hh_id session: egen child_TOT_n_change_FV=mean(child_n_change_FV)
bys hh_id session: egen child_TOT_n_change_fat=mean(child_n_change_fat)
bys hh_id session: egen child_TOT_n_change_sugar=mean(child_n_change_sugar)
replace n_change_FV=child_TOT_n_change_FV if child==1
replace n_change_fat=child_TOT_n_change_fat if child==1
replace n_change_sugar=child_TOT_n_change_sugar if child==1

***creating cumulative changes in consumption for each food categorie
sort id session 
bys id: gen n_change_FV_cumm=n_change_FV if (session<=3) 
bys id: replace n_change_FV_cumm=n_change_FV+n_change_FV[_n-1] if session==4 
bys id: replace n_change_FV_cumm=n_change_FV+n_change_FV_cumm[_n-1] if session==5
bys id: replace n_change_FV_cumm=n_change_FV+n_change_FV_cumm[_n-1] if session==6  

bys id: gen n_change_fat_cumm=n_change_fat if (session<=3) 
bys id: replace n_change_fat_cumm=n_change_fat+n_change_fat[_n-1] if session==4 
bys id: replace n_change_fat_cumm=n_change_fat+n_change_fat_cumm[_n-1] if session==5
bys id: replace n_change_fat_cumm=n_change_fat+n_change_fat_cumm[_n-1] if session==6  


bys id: gen n_change_sugar_cumm=n_change_sugar if (session<=3) 
bys id: replace n_change_sugar_cumm=n_change_sugar+n_change_sugar[_n-1] if session==4 
bys id: replace n_change_sugar_cumm=n_change_sugar+n_change_sugar_cumm[_n-1] if session==5
bys id: replace n_change_sugar_cumm=n_change_sugar+n_change_sugar_cumm[_n-1] if session==6  

* supermarket variables
* children
* replicate values for changes in child consumption (originally in adult survey) for child row in data

bys hh_id session: egen child_shop_fruit_veg_spend=mean(shop_fruit_veg_spend)
bys hh_id session: egen child_shop_unhealthy_spend=mean(shop_unhealthy_spend)
bys hh_id session: egen child_shop_fruit_veg_spend_perc=mean(shop_fruit_veg_spend_perc)
bys hh_id session: egen child_shop_unhealthy_spend_perc=mean(shop_unhealthy_spend_perc)
bys hh_id session: egen child_shop_calories=mean(shop_calories)
bys hh_id session: egen child_shop_fat_spend=mean(shop_fat)
bys hh_id session: egen child_shop_saturates=mean(shop_saturates)
bys hh_id session: egen child_shop_sugar=mean(shop_sugar)
bys hh_id session: egen child_shop_spending=mean(shop_spending)

replace shop_fruit_veg_spend=child_shop_fruit_veg_spend if child==1
replace shop_unhealthy_spend=child_shop_unhealthy_spend if child==1
replace shop_fruit_veg_spend_perc=child_shop_fruit_veg_spend_perc if child==1
replace shop_unhealthy_spend_perc=child_shop_unhealthy_spend_perc if child==1
replace shop_calories=child_shop_calories if child==1
replace shop_fat=child_shop_fat if child==1
replace shop_saturates=child_shop_saturates if child==1
replace shop_sugar=child_shop_sugar if child==1
replace shop_spending=child_shop_spending if child==1


*keeping all variables relevant to sugar consumption
generate calories1=energykcal
generate calories2=shop_calories
generate sugar1=nmesg
generate sugar2=shop_sugar
generate sugar3=n_change_sugar_cumm
generate FV1=FV
generate FV2=shop_fruit_veg_spend
generate FV3=n_change_FV_cumm
generate fat1=saturatesg
generate fat2=shop_fat
generate fat3=n_change_fat_cumm

drop id
rename id_nb id

* creating a dataset stacking all the measures
save "fulldata0.dta", replace

keep hh_id id child treatment session sugar1 FV1 fat1 calories1
rename sugar1 sugar
rename FV1 FV
rename fat1 fat
rename calories1 calories
generate D=1
save "measure1.dta", replace

use "fulldata0.dta", clear
keep hh_id id child treatment session sugar2 FV2 fat2 calories2
rename sugar2 sugar
rename FV2 FV
rename fat2 fat
rename calories2 calories
generate D=2
save "measure2.dta", replace

use "fulldata0.dta", clear
keep hh_id id child treatment session sugar3 FV3 fat3
rename sugar3 sugar
rename FV3 FV
rename fat3 fat
generate D=3
save "measure3.dta", replace

use "measure1.dta", clear
append using "measure2.dta"
append using "measure3.dta"

generate Meal=0
replace Meal=1 if treatment==2

generate Snack=0
replace Snack=1 if treatment==3

generate D1=0
replace D1=1 if D==1
generate D2=0
replace D2=1 if D==2
generate D3=0
replace D3=1 if D==3

generate post=0
replace post=1 if session==3
generate y1=0
replace y1=1 if session==4
generate y2=0
replace y2=1 if session==5
generate y3=0
replace y3=1 if session==6

generate Mpost=0
replace Mpost=1 if treatment==2 & session==3
generate M1=0
replace M1=1 if treatment==2 & session==4
generate M2=0
replace M2=1 if treatment==2 & session==5
generate M3=0
replace M3=1 if treatment==2 & session==6


generate Spost=0
replace Spost=1 if treatment==3 & session==3
generate S1=0
replace S1=1 if treatment==3 & session==4
generate S2=0
replace S2=1 if treatment==3 & session==5
generate S3=0
replace S3=1 if treatment==3 & session==6



*Makes table
***********************************************
xi: reg calories i.Snack|D1 i.session|D1 i.Spost|D1 i.S1|D1 i.S2|D1 i.S3|D1 i.y2|D2 i.S2|D2 i.S3|D2  if (treatment==1 | treatment==3) & child==0, cl(hh_id)
test (_IS2XD1_1=0) (_IS2XD2_1=0) 
test (_IS3XD1_1=0) (_IS3XD2_1=0)
test (_ISpoXD1_1=0) (_IS1XD1_1=0) (_IS2XD1_1=0) (_IS3XD1_1=0) (_IS2XD2_1=0) (_IS3XD2_1=0)

xi: reg sugar i.Snack|D1 i.session|D1 i.Spost|D1 i.S1|D1 i.S2|D1 i.S3|D1 i.S2|D2 i.S3|D2 i.Spost|D3 i.S1|D3 i.S2|D3 i.S3|D3 if (treatment==1 | treatment==3) & child==0, cl(hh_id)
test (_ISpoXD1_1=0) ( _ISpoXD3_1=0)
test (_IS1XD1_1 =0) (_IS1XD3_1=0)
test (_IS2XD1_1 =0) (_IS2XD2_1=0) (_IS2XD3_1=0)
test (_IS3XD1_1=0) (_IS3XD2_1=0)(_IS3XD3_1=0)
test (_ISpoXD1_1=0) ( _ISpoXD3_1=0) (_IS1XD1_1 =0) (_IS1XD3_1=0) (_IS2XD1_1 =0) (_IS2XD2_1=0) (_IS2XD3_1=0) (_IS3XD1_1=0) (_IS3XD2_1=0)(_IS3XD3_1=0)

xi: reg fat i.Snack|D1 i.session|D1 i.Spost|D1 i.S1|D1 i.S2|D1 i.S3|D1 i.S2|D2 i.S3|D2 i.Spost|D3 i.S1|D3 i.S2|D3 i.S3|D3 if (treatment==1 | treatment==3) & child==0, cl(hh_id)
test (_ISpoXD1_1=0) ( _ISpoXD3_1=0)
test (_IS1XD1_1 =0) (_IS1XD3_1=0)
test (_IS2XD1_1 =0) (_IS2XD2_1=0) (_IS2XD3_1=0)
test (_IS3XD1_1=0) (_IS3XD2_1=0)(_IS3XD3_1=0)
test (_ISpoXD1_1=0) ( _ISpoXD3_1=0) (_IS1XD1_1 =0) (_IS1XD3_1=0) (_IS2XD1_1 =0) (_IS2XD2_1=0) (_IS2XD3_1=0) (_IS3XD1_1=0) (_IS3XD2_1=0)(_IS3XD3_1=0)

xi: reg FV i.Snack|D1 i.session|D1 i.Spost|D1 i.S1|D1 i.S2|D1 i.S3|D1 i.S2|D2 i.S3|D2 i.Spost|D3 i.S1|D3 i.S2|D3 i.S3|D3 if (treatment==1 | treatment==3) & child==0, cl(hh_id)
test (_ISpoXD1_1=0) ( _ISpoXD3_1=0)
test (_IS1XD1_1 =0) (_IS1XD3_1=0)
test (_IS2XD1_1 =0) (_IS2XD2_1=0) (_IS2XD3_1=0)
test (_IS3XD1_1=0) (_IS3XD2_1=0)(_IS3XD3_1=0)
test (_ISpoXD1_1=0) ( _ISpoXD3_1=0) (_IS1XD1_1 =0) (_IS1XD3_1=0) (_IS2XD1_1 =0) (_IS2XD2_1=0) (_IS2XD3_1=0) (_IS3XD1_1=0) (_IS3XD2_1=0)(_IS3XD3_1=0)






